<template>
  <div ref="attachmentDetListRef" class="attachDetailList">
    <MyTable
      id="fileId"
      ref="myTableRef"
      :is-mar-class="true"
      :table-data="tableData"
      :columns="colOption"
      :table-operation="btnEnum[prjParams.btnConfig]"
      :col-option-enum="dicLists"
      @propClick="btnClick"
    >
      <template #headerLeft>
        <el-form :model="tableForm" label-width="160px" class="pms-details" size="mini" :disabled="false" :inline="true">
          <el-form-item label="请选择上传文件的项目阶段">
            <el-select
              v-model="tableForm.prjStage"
              clearable
              placeholder="请选择"
              @change="changePrjPhase"
            >
              <!-- class="tablePrjStage" :popper-append-to-body="false" @focus="focusPrjStage" -->
              <el-option
                v-for="item in dicLists['PRO_STAGE']"
                :key="item.dictId"
                :label="item.dictName"
                :value="item.dictId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="项目节点">
            <el-select v-model="tableForm.nodeId" clearable placeholder="请选择" @change="changePrjNode">
              <el-option
                v-for="item in dicLists['ATT_PRO_NODE']"
                :key="item.dictId"
                :label="item.dictName"
                :value="item.dictId"
              />
            </el-select>
          </el-form-item>
        </el-form>
      </template>
      <template #fileName="{ scope }">
        <el-button type="text" @click="preview(scope)">{{ scope.fileName }}</el-button>
      </template>
    </MyTable>
    <pagination
      v-if="pageParam.total > 10"
      :total="pageParam.total"
      :page.sync="pageParam.pageNum"
      :limit.sync="pageParam.pageSize"
      @pagination="doSearch"
    />
    <!-- 替换 / 上传 / 指派签署人 -->
    <el-dialog
      v-if="dialogUpload"
      ref="dialogUploadRef"
      v-dialogDrag
      :append-to-body="true"
      :modal-append-to-body="true"
      :modal="true"
      :close-on-click-modal="false"
      :title="dialogTitle"
      height="60%"
      width="50%"
      class="pms-dialog"
      :visible.sync="dialogUpload"
      @close="() => { isShowStampUnit = false; dialogClosed() }"
    >
      <div class="signatoryBody">
        <UploadAttach
          v-if="isUploadBtn"
          ref="uploadAttachRef"
          :prj-file-type-option="prjFileTypeOption"
          :prj-upload-data="prjUploadData"
          :prj-data="prjData"
          :is-replace="isReplace"
          :is-att-info-item-mar="true"
          @changeSignatory="changeSignatory"
        />
        <ChooseSignatory v-if="isShowStampUnit" ref="chooseSignatoryRef" :prj-data="prjData">
          <template #remarks>
            <Signatory :is-signatory="!isUploadBtn" />
          </template>
        </ChooseSignatory>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button class="pms-zr-button-primary" style="background-color: #eb4b4b; color: #fff;" type="primary" size="small" @click="batchUploadClick">
          提 交
        </el-button>
        <el-button
          class="pms-zr-button-primary pms-zr-ClosedBtn"
          style="background-color: #eb4b4b; color: #fff;"
          size="small"
          @click="() => { dialogUpload = false;isShowStampUnit = false }"
        >
          取 消
        </el-button>
      </div>
    </el-dialog>
    <!-- 预览 -->
    <!-- 文件预览 -->
    <el-dialog
      v-if="dialogFileView"
      ref="dialogViewRef"
      v-dialogDrag
      :append-to-body="true"
      :modal-append-to-body="true"
      :modal="true"
      :close-on-click-modal="false"
      title="预览"
      height="60%"
      width="60%"
      class="pms-dialog"
      :visible.sync="dialogFileView"
      @close="dialogClosed"
    >
      <div class="signatoryPre">
        <FilePreview ref="filePreviewRef" class="filePreviewClass" :file-obj="fileObj" />
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button
          class="pms-zr-button-primary"
          style="background-color: #eb4b4b; color: #fff;"
          size="small"
          @click="dialogFileView = false"
        >
          取 消
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import axios from 'axios'
import MyTable from '@/components/basic/myTable'
import Signatory from '@/components/attachmentInfo/signatory'
import ChooseSignatory from '@/components/attachmentInfo/chooseSignatory'
import UploadAttach from '@/components/attachmentInfo/uploadAttachOld'
import FilePreview from '@/components/business/filePreview.vue'
import SysConst from '@/common/const'
import { getDropdownData } from '@/api/common' // 字典接口
import { getTypeInfoApi, getNodeInfoApi } from '@/api/attachManagement/attachments/attachmentDetails'
import { getQueryObject, disableScroll, enableScroll, msgInfoEl, downloadFileFun } from '@/utils' // singleDownload, mulDownload
import { getSignFlowDocUrlsApi } from '@/api/attachManagement/electronicSign/electronicSignature'
import {
    getPrjFileInfoApi,
    getPrjFileTypeApi,
    batchUploadApi,
    batchDeleteApi,
    getPrjStageApi,
    uploadSignInfoApi,
    assignSignatoryApi, // 电子签章指派签署人
    batchDownloadApi, // 批量下载
    downloadApi, queryBuildModesApi, getPreviewFile, getWPSToken, querySuffix // 单个文件下载
} from '@/api/attachmentInfo'
import { colOption, btnOptionA, btnOptionB, btnOptionC } from '.'
import $ from 'jquery'
const Base64 = require('js-base64').Base64

export default {
    name: 'AttachDetailList',
    components: {
        MyTable,
        Signatory,
        ChooseSignatory,
        UploadAttach,
        FilePreview
    },
    props: {
      queryParams: {
        type: Object,
        default: () => ({})
      }
    },
    data() {
        return {
            tableData: [], // 列表数据
            colOption,
            dicLists: {}, // 字典数据集合
            tableForm: {
                prjStage: '', // 选择项目阶段
                nodeId: '' // 项目节点
            },
            dialogUpload: false, // 上传附件弹框
            isShowStampUnit: false, // 是否展示签署单位
            prjFileTypeOption: [], // 上传文件类型数据选项
            prjUploadData: {}, // 替换数据
            prjData: {}, // 项目数据信息
            isReplace: true, // 是否替换
            fileObj: {}, // 预览文件地址
            dialogFileView: false, // 预览弹框
            isUploadBtn: false, // 是否点击上传或替换
            pageHeight: 180, // 附件列表页面默认高度
            renewalInfo: {}, // 替换时暂存信息
            prjParams: {}, // 页面路由参数集
            // 列表按钮配置枚举
            btnEnum: {
                'A': btnOptionA,
                'B': btnOptionB,
                'C': btnOptionC
            },
            // 分页信息
            pageParam: {
                pageSize: SysConst.PAGESIZE, // 每页显示val条
                pageNum: SysConst.CURRENT_PAGE, // 当前页
                total: SysConst.TOTAL // 总数
            },
            wpsToken: '',
            previewObj:{}
        }
    },
    created() {
        const {
            prjId,
            isChange = '0',
            operateType = '2',
            btnConfig = 'A',
            settPageType
        } = getQueryObject()
        this.prjParams = {
            prjId, // 项目id
            isChange, // 上传方式 0:正常上传的,1:整改的,2:继承的
            btnConfig: this.$route.meta.supplementType === '1' ? 'C' : btnConfig, // 列表按钮配置
            operateType, // 操作类型，1:新增，2:补传
            settPageType // 结算可上传阶段标识
        }
        this.getDictData()
        this.getPrjStage()
        this.doSearch()
        this.getToken()
        this.querySuffix()
    },
    mounted() {
        window.parent.postMessage({ height: 130, type: 'attachment' }, this.$fixIframeArr())
    },
    methods: {
        querySuffix() {
            querySuffix().then((res) => {
                if (+res.code === 200) {
                    this.previewObj = res.data
                }
            })
        },
        getToken() {
            getWPSToken().then((res) => {
                if (+res.code === 200) {
                    this.wpsToken = res.data
                }
            })
        },
        queryPrjFileInfo(params, item) {
            getPrjFileInfoApi(params).then(res => {
                if (+res.code !== 200) {
                    return Promise.reject(res)
                }
                console.log(res, '附件信息')
                this.tableData = res.data.records
                this.pageParam.total = res.data?.total || 0
                this.pageParam.pageSize = item?.limit || SysConst.PAGESIZE
                this.pageParam.pageNum = item?.page || SysConst.CURRENT_PAGE
                this.$nextTick(() => {
                    const h = this.$refs.attachmentDetListRef.clientHeight
                    this.pageHeight = res.data.records.length ? h : 130
                    window.parent.postMessage({ height: this.pageHeight, type: 'attachment' }, this.$fixIframeArr())
                    console.log(h, this.pageHeight, 'this.pageHeight-true')
                })
            })
        },
        doSearch(item) {
            const params = {
                pageNum: item?.page || SysConst.CURRENT_PAGE,
                pageSize: item?.limit || SysConst.PAGESIZE,
                prjId: this.prjParams.prjId,
                ...this.queryParams
            }
            this.queryPrjFileInfo(params, item)
        },
        // 当父组件接收到了子组件this.$emit的通知后就会执行这个方法来接收子组件点击传递过来的数据
        btnClick(fun, row) {
            this[fun](row)
        },
        // 指派签署人按钮
        assign(row) {
            const IsAssignFLag = row.some(item => item.isSignature === '1' && !['1'].includes(item.signatureStatus))
            if (IsAssignFLag) {
                return msgInfoEl({
                    type: 'info',
                    message: '是电子签章且签章状态为待指派时支持指派签署人'
                })
            }
            const isAssign = row.some(item => item.nodeId !== row[0].nodeId)
            if (isAssign) {
                return msgInfoEl({
                    type: 'info',
                    message: '不同节点不支持指派签署人'
                })
            }
            const assignOpen = row.some(item => item.fileSource === '0' && item.isSignature === '0')
            if (assignOpen) {
                return msgInfoEl({
                    type: 'info',
                    message: '手动上传且电子签章为否时的文件不支持指派签署人'
                })
            }
            this.dialogTitle = '指派签署人'
            this.isUploadBtn = false
            this.isReplace = false
            this.isSignatory = true
            this.dialogUpload = true
            this.isShowStampUnit = true
            this.prjData = {
                nodeId: row[0].nodeId,
                docType: row.map(item => item.docTypeCode).join(),
                proStage: row[0].prjStage,
                prjId: this.prjParams.prjId,
                fileId: row.map(item => item.fileId).join(),
                fileSource: row.map(item => item.fileSource).join()
            }
            this.dialogEl('dialogUploadRef')
        },
        // 替换按钮
        async renewal(row) {
            console.log(row, '替换--row')
            if (!['4', '5', '9'].includes(row[0].signatureStatus)) {
                return msgInfoEl({
                    type: 'info',
                    message: '仅支持电子签章的状态为“拒签、作废、转化失败”时'
                })
            }
            const res = await this.getTypeInfo({ prjId: this.prjParams.prjId, prjStage: row[0].prjStage })
            this.getPrjFileType(res.data, { prjStage: row[0].prjStage, nodeId: row[0].nodeId })
            this.dialogTitle = '替换'
            this.isReplace = true
            this.isUploadBtn = true
            this.dialogUpload = true
            this.prjUploadData = row[0]
            this.prjData = {
                nodeId: row[0].nodeId,
                docType: row[0].docTypeCode,
                proStage: row[0].prjStage,
                prjId: this.prjParams.prjId,
                fileId: row[0].fileId
            }
            this.renewalInfo = this.prjData
            this.dialogEl('dialogUploadRef')
        },
        // 下载
        download(row) {
            const fileDownloadNo = row.find(item => item.fileId === '' || item.fileId === null || item.fileId === undefined) || {}
            if (JSON.stringify(fileDownloadNo) !== '{}') {
                return msgInfoEl({
                    type: 'info',
                    message: `当前选择范围中存在未上传文件，请上传或取消勾选该文件再进行下载`
                })
            }
            const fileName = row.length > 1 ? '附件信息.zip' : row[0].fileName
            // 单个文件下载时的参数
            const params = {
                fileId: row[0].fileId,
                fileName: row[0].fileName
            }
            // 多个文件下载时的参数
            const batchParams = row.map(item => ({
                fileId: item.fileId,
                fileName: item.fileName
            }))
            if (row.length > 1) {
                // mulDownload(row, fileName)
                // 批量下载
                batchDownloadApi({ fileMap: batchParams }).then(res => {
                    downloadFileFun(res, fileName)
                })
            } else {
                // singleDownload(row, fileName)
                // 单个文件下载
                downloadApi(params).then(res => {
                    downloadFileFun(res, fileName)
                })
            }
        },
        // 删除附件按钮
        delete(row) {
            const isDel = row.some(item => item.isSignature !== '1' || ['1','3', '4', '5', '9'].includes(item.signatureStatus))
            if (!isDel) {
                return msgInfoEl({
                    type: 'info',
                    message: '文件为电子签章时，仅支持签署状态为待指派、拒签、作废、已签署完成、转换失败时才能删除'
                })
            }
            const isRel = row.some(item => item.fileSource !== '0')
            if (isRel) {
                return msgInfoEl({
                    type: 'info',
                    message: '仅支持文件获取方式为手动上传的文件'
                })
            }
            const isRemove = row.some(item => item.nodeId !== row[0].nodeId)
            if (isRemove) {
                return msgInfoEl({
                    type: 'info',
                    message: '不同节点不支持批量删除'
                })
            }
            // const fileIdList = row.map(item => item.fileId)
            // const params = {
            //     fileId: fileIdList.join(),
            //     supplementType: this.$route.meta.supplementType
            // }
            const params = [];
            row.forEach((item)=>{
                params.push({
                    fileId:item.fileId,
                    prjId:item.prjId,
                    supplementType:this.$route.meta.supplementType,
                })
            })
            if(params.length > 0){
                this.deleteConfirm(params);
            }else{
                return msgInfoEl({
                    type: 'error',
                    message: '没有文件可进行删除'
                })
            }
        },
        deleteConfirm(params){
            const contentBody = window.top.document.body
            this.$confirm('确认删除所选数据, 是否继续?', '删除', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                cancelButtonClass: 'pms-zr-button',
                confirmButtonClass: 'pms-zr-button-primary',
                type: 'warning',
                closeOnClickModal: false
            }).then(() => {
                batchDeleteApi(params).then(res => {
                    if (+res.code !== 200) {
                        return Promise.reject(res)
                    }
                    this.doSearch()
                    this.$refs.myTableRef.clearSelection()
                    // this.$refs.myTableRef.toggleRowSelection(row)
                    msgInfoEl({
                        type: 'success',
                        message: res.message
                    })
                    enableScroll(contentBody)
                })
            }).catch(() => {
                enableScroll(contentBody)
                console.log('取消删除了')
            })
            // el-message-box__wrapper
            // 将弹框挂载在最外层
            this.$nextTick(() => {
                const msgBox = document.querySelector('.el-message-box__wrapper')
                contentBody.appendChild(msgBox)
                disableScroll(contentBody)
            })
        },
        // 下拉框获取焦点事件
        // focusPrjStage() {
        //     // 设置下拉框样式
        //     const tablePrjStage = document.querySelector('.tablePrjStage')
        //     const scrollbar = tablePrjStage.querySelector('.el-scrollbar__wrap')
        //     const h = this.$refs.attachmentDetListRef.clientHeight - 26
        //     scrollbar.style.height = h + 'px'
        //     scrollbar.style.overflowX = 'hidden'
        //     scrollbar.style.marginBottom = '-8px'
        // },
        // 改变项目阶段事件
        changePrjPhase() {
            this.tableForm.prjStage ? this.getNodeInfo(this.tableForm.prjStage) : this.$set(this.dicLists, 'ATT_PRO_NODE', [])
            this.tableForm.nodeId = ''
        },
        // 改变项目节点事件
        async changePrjNode() {
            if (!this.tableForm.nodeId) {
                return
            }
            const res = await this.getTypeInfo({ prjId: this.prjParams.prjId, prjStage: this.tableForm.prjStage })
            await this.getPrjFileType(res.data, this.tableForm)
            this.dialogTitle = '上传'
            this.isReplace = false
            this.isUploadBtn = true
            this.dialogUpload = true
            this.prjUploadData = {}
            this.prjData = {
                nodeId: this.tableForm.nodeId,
                proStage: this.tableForm.prjStage,
                prjId: this.prjParams.prjId,
                prjType: res.data.prjType
            }
            this.dialogEl('dialogUploadRef')
        },
        // 获取上传前的参数
        async getTypeInfo(params) {
            const res = await getTypeInfoApi(params)
            if (res.success) {
                this.prjParams = { ...this.prjParams, ...res.data }
                console.log(this.prjParams, '上传前的参数--res')
                return res
            }
        },
        // 上传附件中-签署人改变事件
        changeSignatory(val1, val2) {
            this.isShowStampUnit = val1
            this.prjData = {
                docType: val2,
                proStage: this.isReplace ? this.renewalInfo.proStage : this.tableForm.prjStage,
                prjId: this.prjParams.prjId,
                fileId: this.isReplace ? this.renewalInfo.fileId : '',
                nodeId: this.isReplace ? this.renewalInfo.nodeId : this.tableForm.nodeId
            }
        },
        // 上传事件-替换
        batchUploadClick() {
            const uploadForm = this.isUploadBtn ? this.$refs.uploadAttachRef.uploadForm : {}
            // const signatoryData = this.$refs.chooseSignatoryRef.getSelectionSignatory
            // 备注：uploadForm.isEleSign === '0' => 附件上传; uploadForm.isEleSign === '1' => 电子签章上传
            if (uploadForm.isEleSign === '0') {
                this.attachmentUpload(uploadForm)
            } else {
                this.isUploadBtn ? this.eleSignUpload(uploadForm) : this.assignSignatory(this.prjData, this.prjData.fileId)
            }
        },
        // 附件上传
        attachmentUpload(uploadForm) {
            const {
                prjId, // 项目id
                fileSupplierCode = '', // 供应商编码
                isChange, // 上传方式 0:正常上传的,1:整改的,2:继承的
                prjType,
                buildModes,
                towerType,
                roomType,
                operateType // 操作类型，1:新增，2:补传
            } = this.prjParams
            if (this.isUploadBtn && !uploadForm.fileList.length) {
                return msgInfoEl({
                    type: 'info',
                    message: '请上传文件'
                })
            }

            const params = {
                file: uploadForm.fileList[0].raw, // 文件
                docFileType: uploadForm.docTypeCode, // 文件类型
                prjId, // 项目id
                activityId: this.tableForm.nodeId, // 流程id
                prjStage: this.tableForm.prjStage, // 项目阶段
                prjType,
                buildModes,
                towerType,
                roomType,
                fileSupplierCode, // 供应商编码
                isChange, // 上传方式 0:正常上传的,1:整改的,2:继承的
                operateSystem: '0', // 操作系统，0:PMS,1:施工管理
                operateType, // 操作类型，1:新增，2:补传
                supplementType: this.$route.meta.supplementType
            }
            const formData = new FormData()
            Object.keys(params).forEach(key =>
                formData.append(key, params[key])
            )
            batchUploadApi(formData).then(res => {
                if (+res.code !== 200) {
                    return Promise.reject(res)
                }
                this.dialogUpload = false
                this.doSearch()
                msgInfoEl({
                    type: 'success',
                    message: res.message
                })
            })
        },
        repairEleSignUploadOne(types1,types2){
          return   this.isReplace ? types1 : types2
        },
        // 电子签章上传
        eleSignUpload(uploadForm) {
            const {
                prjId, // 项目id
                isChange, // 上传方式 0:正常上传的,1:整改的,2:继承的
                prjType,
                buildModes,
                towerType,
                roomType,
                operateType // 操作类型，1:新增，2:补传
            } = this.prjParams
            if (!uploadForm.fileList.length) {
                return msgInfoEl({
                    type: 'info',
                    message: '请上传文件'
                })
            }
            const params = {
                file: uploadForm.fileList[0].raw, // 文件
                docFileType: uploadForm.docTypeCode, // 文件类型
                prjId, // 项目id
                // prjStage: this.isReplace ? this.renewalInfo.proStage : this.tableForm.prjStage, // 项目阶段
                prjStage:this.repairEleSignUploadOne(this.renewalInfo.proStage,this.tableForm.prjStage),
                isChange, // 上传方式 0:正常上传的,1:整改的,2:继承的
                operateType, // 操作类型，1:新增，2:补传
                operateSystem: '0', // 操作系统 0:PMS,1:施工管理
                // oldDocId: this.isReplace ? this.renewalInfo.fileId : '',
                // activityId: this.isReplace ? this.renewalInfo.nodeId : this.tableForm.nodeId, // 流程id
                oldDocId: this.repairEleSignUploadOne(this.renewalInfo.fileId,''),
                activityId:this.repairEleSignUploadOne(this.renewalInfo.nodeId,this.tableForm.nodeId), // 流程id
                prjType,
                buildModes,
                towerType,
                roomType,
                // isReplaceFlag: this.isReplace ? 'Y' : 'N',
                isReplaceFlag: this.repairEleSignUploadOne('Y','N'),
                supplementType: this.$route.meta.supplementType
            }
            const formData = new FormData()
            Object.keys(params).forEach(key =>
                formData.append(key, params[key])
            )
            uploadSignInfoApi(formData).then(res => {
                if (+res.code !== 200) {
                    return Promise.reject(res)
                }
                if (this.isShowStampUnit) {
                    this.assignSignatory({
                        docType: uploadForm.docTypeCode,
                        // nodeId: this.isReplace ? this.renewalInfo.nodeId : this.tableForm.nodeId,
                        // proStage: this.isReplace ? this.renewalInfo.proStage : this.tableForm.prjStage,
                        nodeId: this.repairEleSignUploadOne(this.renewalInfo.nodeId,this.tableForm.nodeId),
                        proStage: this.repairEleSignUploadOne(this.renewalInfo.proStage,this.tableForm.prjStage),
                        fileSource: ''
                    }, res.data)
                } else {
                    this.dialogUpload = false
                    this.doSearch()
                    this.dialogClosed()
                    msgInfoEl({
                        type: 'success',
                        message: res.message
                    })
                }
            })
        },
        // 指派签署人接口
        assignSignatory(uploadForm, oldDocId) {
            const params = {
                docFileType: uploadForm.docType,
                prjId: this.prjParams.prjId,
                activityId: uploadForm.nodeId, // 项目阶段,
                prjStage: uploadForm.proStage, // 项目阶段
                oldDocId,
                fileSource: uploadForm.fileSource
            }
            assignSignatoryApi(params).then(res => {
                if (+res.code !== 200) {
                    return Promise.reject(res)
                }
                this.dialogUpload = false
                this.doSearch()
                this.dialogClosed()
                msgInfoEl({
                    type: 'success',
                    message: res.message
                })
                console.log('指派签署人成功')
            })
        },
        getUserId(){
            let str='';
            if(sessionStorage.getItem('SET_LOGINDATA')){
              str = JSON.parse(sessionStorage.getItem('SET_LOGINDATA')).staffId
            }else if(sessionStorage.getItem('userInfo')){
              str = JSON.parse(sessionStorage.getItem('userInfo')).staffId
            }else{
              console.log('')
            }
            console.log('str',str)
            return str;
        },
        // 点击文件名称-预览
        async preview(row) {
            if (row.isSignature === '1') {
                this.getSignFlowDocUrls(row.fileViewId)
                return
            } else {
                const types = row.fileName.substring(row.fileName.lastIndexOf('.') + 1)
                const previewArray = Object.keys(this.previewObj);
                if (previewArray.includes(types)) {
                    const params = {
                        fileId: row.fileId,
                        type: this.previewObj[types],
                        userId: this.getUserId(),
                        token: this.wpsToken
                    }
                    getPreviewFile(params).then((res) => {
                        // if(+res.code===200){
                        //     const newWin = window.open()
                        //     const form = $("<form method='post'></form>")
                        //     form.attr({ action: res.data })
                        //     form.appendTo(newWin.document.body)
                        //     form.submit()
                        // }
                        if (+res.code === 200 && res.data) {
                            window.open(res.data, '_blank')
                        }
                    })
                } else {
                    return msgInfoEl({
                        type: 'info',
                        message: `所选文件不支持预览`
                    })
                }
            }
            // let res = {}
            // const params = {
            //     fileId: row.fileId,
            //     fileName: row.fileName
            // }
            // await downloadApi(params).then(r => {
            //     res = r
            // })
            // const blob = new Blob([res.data], { type: 'application/pdf;charset-UTF-8' })
            // const url = window.URL.createObjectURL(blob)
            // row.filePath = url
            // this.fileObj = {}
            // if (!row.filePath) {
            //     return msgInfoEl({
            //         type: 'info',
            //         message: `所选${row.fileName}文件不支持预览`
            //     })
            // }
            // const types = row.fileName.substring(row.fileName.lastIndexOf('.') + 1)
            // if (['word', 'docx', 'excel', 'xlsx'].includes(types)) {
            //     console.log(types, '12')
            //     window.open(this.$router.resolve({
            //         name: 'FilePreview',
            //         query: {
            //             type: types,
            //             fileSrc: row.filePath
            //         }
            //     }).href, '_blank')
            //     return
            // }
            // if (['pdf'].includes(types)) {
            //     window.open(row.filePath, '_blank')
            //     return
            // }
            // if (['pptx', 'ppt', 'doc', 'xls'].includes(types)) {
            //     // window.open(`${process.env.VUE_APP_BASE_API}preview/onlinePreview?url=${encodeURIComponent(Base64.encode(row.filePath))}`, '_blank')
            //     return msgInfoEl({
            //         type: 'info',
            //         message: `所选文件不支持预览`
            //     })
            // }
            // if (['jpg', 'png', 'jpeg', 'bmp', 'mp3', 'mp4', 'webm', 'ogg', 'aac', 'wav'].includes(types)) {
            //     this.fileObj = {
            //         type: types,
            //         fileSrc: row.filePath
            //     }
            //     this.dialogFileView = true
            //     this.dialogEl('dialogViewRef')
            // } else if (['txt'].includes(types)) {
            //     axios.get(row.filePath, {
            //         responseType: 'blob',
            //         transformResponse: [
            //             async function(data) {
            //                 // txt转码
            //                 return await new Promise((resolve) => {
            //                     const reader = new FileReader()
            //                     reader.readAsText(data, 'UTF-8') // GBK UTF-8
            //                     reader.onload = () => {
            //                         resolve(reader.result)
            //                     }
            //                 })
            //             }
            //         ]
            //     }).then(res => {
            //         res.data.then((data) => {
            //             this.fileObj = {
            //                 type: types,
            //                 fileSrc: data
            //             }
            //         })
            //     })
            //     this.dialogFileView = true
            //     this.dialogEl('dialogViewRef')
            // } else {
            //     msgInfoEl({
            //         type: 'info',
            //         message: '不支持预览此文件'
            //     })
            // }
            // console.log(row, types, '预览')
        },
        // 电子签章预览
        getSignFlowDocUrls(id) {
            getSignFlowDocUrlsApi({ id }).then(res => {
                if (+res.code !== 200) {
                    return Promise.reject(res)
                }
                if (res.data) {
                    axios.get(res.data, {
                        responseType: 'blob',
                        cache: true,
                        headers: {
                            'Content-Disposition': 'inline'
                        }
                    }).then(r => {
                            const blob = new Blob([r.data], { type: 'application/pdf;charset-UTF-8' })
                            // const blob = new Blob([r.data], { type: r.headers['content-type'] })
                            const url = window.URL.createObjectURL(blob)
                            window.open(url, '_blank')
                            URL.revokeObjectURL(url) // 释放内存
                    })
                }
            })
        },
        // 获取附件允许上传文件类型数据
        async getPrjFileType(res, prjRes) {
            const params = {
                ...res,
                ...prjRes
            }
            if (res.prjType === 'Z') {
                const paramsBuild = {
                    prjId: this.prjParams.prjId,
                    prjType: res.prjType
                }
                await queryBuildModesApi(paramsBuild).then((result) => {
                    if (+result.code === 200) {
                        if (result.data.projectAttribution === '01') {
                            params.buildModes = '01'
                        } 
                         if (result.data.projectAttribution === '02') {
                            params.buildModes = '09'
                        }
                    }
                })
            }
            getPrjFileTypeApi(params).then(res_s => {
                if (+res_s.code !== 200) {
                    return Promise.reject(res_s)
                }
                this.prjFileTypeOption = res_s.data
            })
        },
        // 获取字典数据
        async getDictData() {
            const arr = ['SIGN_STATE2']
            const promises = arr.map(item => getDropdownData(item))
            const results = await Promise.all(promises)
            arr.forEach((item, i) => {
                this.$set(this.dicLists, item, results[i].data ?? [])
            })
            this.$set(this.dicLists, 'FILE_UPLOAD_MODES', SysConst.UPLOAD_MODES)
        },
        // 获取项目阶段字典
        async getPrjStage() {
            const res = await getPrjStageApi({ settPageType: this.prjParams.settPageType })
            const data = res.data.map(item => ({
                dictId: item.key,
                dictName: item.value
            }))
            this.$set(this.dicLists, 'PRO_STAGE', data)
        },
        // 获取项目节点字典
        async getNodeInfo(val) {
            const res = await getNodeInfoApi({ prjId: this.prjParams.prjId, settPageType: this.prjParams.settPageType, prjStage: val ?? '' })
            if (!res.data.length) {
                msgInfoEl({
                    type: 'info',
                    message: '此项目阶段下项目节点为空'
                })
            }
            this.$set(this.dicLists, 'ATT_PRO_NODE', res.data)
        },
        // 将弹框挂载在最外层
        dialogEl(refName) {
            // 将弹框挂载在最外层
            const contentBody = window.top.document.body
            this.$nextTick(() => {
                const dialogModal = document.querySelector('.v-modal')
                contentBody.appendChild(this.$refs[refName].$el)
                contentBody.appendChild(dialogModal)
                disableScroll(contentBody)
            })
        },
        // 关闭弹框
        dialogClosed() {
            const contentBody = window.top.document.body
            enableScroll(contentBody)
        }
    }
}
</script>

<style lang="scss" scoped>
.attachDetailList {
    width: 100%;
    height: auto;
}
.pms-details {
    margin-right: 10px;
    display: flex;
    width: auto;
    justify-content: flex-end;
    .el-form-item {
        width: auto;
    }
}
::v-deep .btnBox-btns {
    margin-right: 10px;
}
.el-button--text {
    color: #02A7F0;
}
.signatoryBody {
    min-height: 170px;
    max-height: 420px;
    overflow-y: auto;
    overflow-x: hidden;
}
.signatoryPre {
    max-height: 420px;
    overflow-y: auto;
    overflow-x: hidden;
}
.el-button--primary {
    color: #fff;
}
::v-deep .pms-details .el-form-item .el-form-item__content {
    // width: 100%;
    width: 140px;
}
::v-deep .btnBox-btn {
    padding-right: 10px;
}
::v-deep .el-form-item .el-form-item__label {
    line-height: 20px !important;
}
</style>
